#include "lom-events.hh"


using namespace boost;
using namespace licada;

namespace lom
{
    LomEventSystem::~LomEventSystem()
    {
    }
	
    void LomEventSystem::addEventHandler( ILomEventHandler* system )
    {
	TEventHandlerVector::iterator find = std::find( eventSystems.begin(), eventSystems.end(), system );
	if ( find == eventSystems.end())
	    eventSystems.push_back( system );
    }
    void LomEventSystem::removeEventHandler( ILomEventHandler* system )
    {
	erase_if( eventSystems, bind( std::equal_to<ILomEventHandler*>(), _1, system ));
    }
    
    void LomEventSystem::event( TNameType name, const TValueVector& args )
    {
	do_all( eventSystems, bind( &ILomEventHandler::event, _1, name, ref(args) ) );
    }

    void LomEventSystem::classCreated( const LomClass& cls ) 
    { 
	do_all(eventSystems, bind( &ILomEventHandler::classCreated, _1, ref(cls) ));
    }
    
    void LomEventSystem::instanceCreated( THandle instance ) { 
	do_all( eventSystems, bind( &ILomEventHandler::instanceCreated, _1, instance ) );
    }
    
    void LomEventSystem::instanceDestroyed( THandle instance ) { 
	do_all( eventSystems, bind(&ILomEventHandler::instanceDestroyed, _1, instance ) );
    }
    
    void LomEventSystem::propertyEvent( THandle instance
					, licada::uint32 index
					, const LomValue& finalValue ) { 
	do_all(eventSystems
	       , bind( &ILomEventHandler::propertyEvent, _1
		       , instance, index, ref(finalValue) ));
    }
    void LomEventSystem::rootObjectSet( TNameType name, const LomValue& value ) {
	do_all( eventSystems, bind( &ILomEventHandler::rootObjectSet, _1, name, ref(value) ) );
    }
}
